<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>AllModules</title>
		<meta name="keywords" content="">
		<meta name="description" content=""> {include file="common/default" /}
	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeIn">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox ">
						<div class="ibox-title">
							<h5>AllModules</h5>
						</div>
						<div class="ibox-content">
							<div class="row mb-12">
								<div class="col-md-4 text-left">
								
                               
                            </button>

								</div>
								
							</div>
							<table class="layui-hide" id="test" lay-filter="test"></table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" style="background:#0096fa;" lay-event="detail">修改</a>

			<a class="layui-btn layui-btn-danger layui-btn-xs" style="background:#5c8199;" lay-event="del">删除</a>

		</script>
		{include file="common/defaultBack" /}
		<!-- Page-Level Scripts -->
		<script>
			$(document).ready(function() {
				var path = '__PUBLIC__/static/';
				$("#addBtn").click(function() {
					var index = layer.open({
						title: '新增',
						type: 2,
						content: "{:url('Port/port_add')}",
						area: ['80%', '90%'],
						resize: true,
						fix: false,
						maxmin: false
					});
				});

				layui.use('laydate', function() {
					var laydate = layui.laydate;
					lay('.test-item').each(function() {
						laydate.render({
							elem: this,
							trigger: 'click'
						});
					});
				});

				layui.use('table', function() {
					var table = layui.table;
					//方法级渲染
					table.render({
						elem: '#test',
						url: "{:url('Port/port_info')}",

						cols: [
							[{
									field: 'Mno',
									title: 'Mno',
									sort: true,
									fixed: true
								}, {
									field: 'Title',
									title: 'Title',
									sort: true
								}, {
									field: 'Convenior',
									title: 'Convenior',
									sort: true
								}, {
									field: 'Introduction',
									title: 'Introduction',
									sort: true
								} 
								

							]
						],
						limit: 8,
						loading: true, //请求数据时，是否显示loading
						id: 'test',
						page: true,

					});
					$('.searchBtn').on('click', function() {
						loadData();
					});

					function loadData() {

						var demoReload = $('#demoReload').val();

						//执行重载
						table.reload('test', {
							page: {
								curr: 1 //重新从第 1 页开始
							},
							where: {
								name: demoReload
							},
							url: "{:url('Risk/fuzzy_query')}",
							method: 'post'

						});

					}

					table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
						var data = obj.data, //获得当前行数据,
							layEvent = obj.event; //获得 lay-event 对应的值
						var id = data.id;
						if(layEvent === 'detail') {
							layer.open({
								title: '修改',
								type: 2,
								content: "{:url('Port/port_modify')}?" + id,
								area: ['80%', '90%'],
								resize: true,
								fix: false
							});
						} else if(layEvent === 'del') {

							layer.confirm('真的删除行么', function(index) {
								obj.del(); //删除对应行（tr）的DOM结构
								layer.close(index);
								//向服务端发送删除指令
								$.ajax({
									type: "post",
									url: "{:url('Port/port_del')}",
									async: true,
									data: "id=" + id,
									success: function(data) {
										console.log(data)
									},
									error: function() {
										console.log('err')
									}
								});
							});
						}
					});

					//表格全选
					layui.table.on('checkbox(allChoose)', function(data) {

						var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');

						child.each(function(index, item) {
							item.checked = data.elem.checked;
						});
						form.render('checkbox');
					});
				});
			});
		</script>
	</body>

</html>